package com.hhkj.admin.common.validator;

import lombok.Getter;
import org.springframework.context.ApplicationContext;

import java.util.List;

public class ValidatorAssembler<T extends AbstractValidatorChain> {

    public ApplicationContext applicationContext;

    @Getter
    private AbstractValidatorChain head;

    public ValidatorAssembler(ApplicationContext applicationContext, List<T> chainList) {
        this.applicationContext = applicationContext;
        T pre = null;
        head = new ValidatorChainStarter();

        for (int i = 0; i < chainList.size(); i++) {
            T value = chainList.get(i);
            if (pre != null) {
                pre.setNext(value);
            } else {
                head.setNext(value);
            }
            pre = value;
        }
    }
}
